package arbre.utils;

import java.io.Serializable;



public class Point implements Comparable<Point>,  Serializable{
	/**
	 * 
	 */
	private static long serialVersionUID = 8355867625350877648L;
	private float x;
	private float y;
	
	public Point(){
		
	}
	public Point(float x, float y) {
		super();
		this.x = x;
		this.y = y;
	}
	
	public Point homethetie(float lambda) {
		return new Point(x*lambda, y*lambda);
	}

	public Point translation(Segment s) {
		return new Point(x+s.getFin().x-s.getDebut().x,y+s.getFin().y-s.getDebut().y);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Float.floatToIntBits(x);
		result = prime * result + Float.floatToIntBits(y);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Point other = (Point) obj;
		if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x))
			return false;
		if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y))
			return false;
		return true;
	}
	
	public int compareTo(Point p) {
		if (x < p.x)
			//p est a droite de this
			return -1;
		else if (x>p.x)
			//p est a gauche de this
			return 1;
		else if (y < p.y)
			//p est en haut de this
			return -1;
		else if (y>p.y)
			//p est en dessous de this
			return 1;
		else 
			return 0;
	}
	
	
	@Override
	public String toString() {
		return "<point x=\""+x+"\" y=\""+y+"\"/>\n";
	}
	
	public String toDot(){
		return "(" + new Float(x).toString().replace(".", "_") + "," + new Float(y).toString().replace(".", "_") + ")";
	}

	public float getX() {
		return x;
	}

	public void setX(float x) {
		this.x = x;
	}

	public float getY() {
		return y;
	}

	public void setY(float y) {
		this.y = y;
	}

	public String toXml() {
		return toString();
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public static void setSerialversionuid(long serialversionuid) {
		serialVersionUID = serialversionuid;
	}

	
}